package ui;

import engine.AlgoKMeans;
import engine.AlgoKMeans.Distance;
import engine.KMeansResult;
import engine.Stats;
import engine.VectorTI;
import java.awt.Font;
import java.io.File;
import java.util.ArrayList;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ExecutionException;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import normalisation.Normalizer;
import normalisation.Normalizer.EncodageType;
import normalisation.Normalizer.NormalisationType;
import utilities.MapTools;
import utilities.VersionComparator;

public class UserInterface extends javax.swing.JFrame {

    private Stats stats;
    private Normalizer normalizer;
    private AlgoKMeans kmeans;

    public UserInterface() {
        //System.out.println("JRE Version: " + System.getProperty("java.version"));

        //Extinction si version de java < 1.7
        String versionClient = System.getProperty("java.vm.specification.version");
        if (VersionComparator.compare(versionClient, "1.7") < 0) {
            displayErrorPopup("Ce programme necessite la JVM 1.7 ou supérieur. Veuillez mettre a jour la JVM. (Version detectee: " + versionClient + ").");
            System.exit(0);
        }

        initComponents();
        initRadioButtonGroups();

        this.setLocationRelativeTo(null);
    }

    private void initRadioButtonGroups() {
        buttonGroupNormalisation.add(rbTokenisation);
        buttonGroupNormalisation.add(rbRacinisation);
        buttonGroupNormalisation.add(rbLemmatisation);

        buttonGroupEncodage.add(rbISO);
        buttonGroupEncodage.add(rbUTF8);

        buttonGroupDistances.add(rbDistEuclidienne);
        buttonGroupDistances.add(rbDistManhattan);
        buttonGroupDistances.add(rbDistMinkowski);

        buttonGroupCondArretKMeans.add(rbIterations);
        buttonGroupCondArretKMeans.add(rbDistMax);
    }

    //Affiche une popup d'erreur
    public void displayErrorPopup(String msg) {
        JOptionPane.showMessageDialog(this, msg, "Erreur", JOptionPane.ERROR_MESSAGE);
    }

    //Crée un normalizer à partir de l'interface
    private Normalizer makeNormaliser() {
        //Type de normalisation
        NormalisationType normalisationType = NormalisationType.Tokenisation;
        if (rbLemmatisation.isSelected()) {
            normalisationType = NormalisationType.Lemmatisation;
        } else if (rbRacinisation.isSelected()) {
            normalisationType = NormalisationType.Racinisation;
        }

        //Type d'encodage
        EncodageType encodageType = EncodageType.UTF_8;

        if (rbISO.isSelected()) {
            encodageType = EncodageType.ISO_8859_1;
        }

        return new Normalizer(normalisationType,
                encodageType,
                cbFilterAccents.isSelected(),
                cbFilterPonctuation.isSelected(),
                cbFiltrerNombres.isSelected(),
                cbFilterSW.isSelected(),
                txtStopWordPath.getText(),
                cbFilterOneOccurence.isSelected());
    }

    //Bouton Calculer Statistiques
    private void btnMakeStats() {
        //Erreur si le chemin du fichier train est incorrect
        if (!(new File(txtTrainPath.getText())).exists()) {
            displayErrorPopup("Le fichier " + txtTrainPath.getText() + " est introuvable.");
            return;
        }

        //Si filtrer stopWord check, mais chemin incorrect, popup d'erreur
        if (cbFilterSW.isSelected() && !(new File(txtStopWordPath.getText()).exists())) {
            displayErrorPopup("Le fichier " + txtStopWordPath.getText() + " est introuvable.");
            return;
        }

        //Désactiver pour éviter un 2ème clic involontaire
        btnMakeStats.setEnabled(false);

        //Création du normalizer
        this.normalizer = makeNormaliser();

        this.stats = new Stats(txtTrainPath.getText(), normalizer);
        this.stats.setGui(this);
        this.stats.execute();
        //Appel statsFilled() quand le thread termine
    }

    //Stats a terminé
    public void statsFilled() {

        //Update statistiques sur l'UI
        lblUniqueWords.setText(stats.getUniqueWordsCount().toString());
        lblTotalWords.setText(stats.getTotalWordsCount().toString());
        lblTweetCount.setText(stats.getTweetsCount().toString());
        lblAvgWordCount.setText(stats.getAvgWordCount().toString());

        //Top 20 & Flop 20
        panelTop20.removeAll();
        panelFlop20.removeAll();
        Integer wordsToDisplay = 20;
        Integer mapIndexPosition = 0;
        JLabel currentLabel;

        TreeMap<String, Integer> corpusTfMap = MapTools.getSortedMap(this.stats.getCorpusTfMap());

        for (Map.Entry<String, Integer> e : corpusTfMap.entrySet()) {

            //Top 20
            if (mapIndexPosition < wordsToDisplay) {
                currentLabel = new JLabel(e.getKey() + ", ");
                currentLabel.setFont(currentLabel.getFont().deriveFont(15f).deriveFont(Font.BOLD));
                currentLabel.setToolTipText(e.getValue() + " occurences");
                panelTop20.add(currentLabel);
            }

            //Flopp 20
            if (mapIndexPosition >= corpusTfMap.size() - wordsToDisplay) {
                currentLabel = new JLabel(e.getKey() + ", ");
                currentLabel.setFont(currentLabel.getFont().deriveFont(15f).deriveFont(Font.BOLD));
                currentLabel.setToolTipText(e.getValue() + " occurence(s)");
                panelFlop20.add(currentLabel);
            }

            mapIndexPosition++;
        }

        this.repaint();
        
        //Réactiver le bouton et le renommer
        btnMakeStats.setText("Recalculer");
        btnMakeStats.setEnabled(true);
        
        //Activer Algo KMeans
        btnKMeans.setEnabled(true);
    }

    //Barre de progression Stats
    public void updateBarStats(Integer progress) {
        barMakeStats.setValue(progress);
        lblMakeStats.setText(progress + "%");
    }

    //Barre de progression K-moyennes
    public void updateBarKMeans(Integer progress) {
        barKmeans.setValue(progress);
        lblKmeans.setText(progress + "%");
    }

    //Bouton Calculer K-moyennes
    private void btnKMeans() {
        //Désactiver pour éviter un clic involontaire
        btnKMeans.setEnabled(false);
        btnMakeStats.setEnabled(false);

        Distance distanceType;

        if (rbDistManhattan.isSelected()) {
            distanceType = Distance.Manhattan;
        } else if (rbDistMinkowski.isSelected()) {
            distanceType = Distance.Minkowski;
        } else {
            distanceType = Distance.Euclidienne;
        }


        Integer nbIterations = -1;
        Double distMaxTreshold = null;
        if (rbIterations.isSelected()) {
            nbIterations = Integer.parseInt(txtIterations.getText());
        } else {
            distMaxTreshold = Double.parseDouble(txtDistMax.getText());
        }

        Integer cluserCount = Integer.parseInt(txtClusterCount.getText());
        Integer minkowskiParam = Integer.parseInt(txtMinkowskiParam.getText());

        this.kmeans = new AlgoKMeans(this.stats.getTweets(),
                cluserCount,
                distanceType,
                minkowskiParam,
                nbIterations,
                distMaxTreshold);
        kmeans.setGui(this);
        kmeans.execute();
    }

    public void kMeansFinished() {
        System.out.println("KMeans Finished.");
        try {
            KMeansResult result = kmeans.get();

            //On affiche le vecteur de chaque cluster
            for (Map.Entry<Integer, ArrayList<VectorTI>> e : result.mapCentroidToVectors.entrySet()) {
                System.out.println("k" + e.getKey() + "(" + e.getValue().size() + ") : " + result.centroids[e.getKey()].toShortString(this.stats.getVocabulary(), 0.10));
            }
        } catch (InterruptedException | ExecutionException ex) {
        }
        
        //Réactivation des boutons
        btnKMeans.setEnabled(true);
        btnMakeStats.setEnabled(true);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroupNormalisation = new javax.swing.ButtonGroup();
        buttonGroupEncodage = new javax.swing.ButtonGroup();
        buttonGroupDistances = new javax.swing.ButtonGroup();
        buttonGroupCondArretKMeans = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        txtTrainPath = new javax.swing.JTextField();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        lblUniqueWords = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        lblTotalWords = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        lblTweetCount = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        lblAvgWordCount = new javax.swing.JLabel();
        btnMakeStats = new javax.swing.JButton();
        barMakeStats = new javax.swing.JProgressBar();
        lblMakeStats = new javax.swing.JLabel();
        panelTop20 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        panelFlop20 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        txtTestPath = new javax.swing.JTextField();
        jTabbedPane2 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        cbFilterSW = new javax.swing.JCheckBox();
        cbFilterPonctuation = new javax.swing.JCheckBox();
        cbFiltrerNombres = new javax.swing.JCheckBox();
        txtStopWordPath = new javax.swing.JTextField();
        cbFilterAccents = new javax.swing.JCheckBox();
        cbFilterOneOccurence = new javax.swing.JCheckBox();
        jPanel6 = new javax.swing.JPanel();
        rbISO = new javax.swing.JRadioButton();
        rbUTF8 = new javax.swing.JRadioButton();
        jPanel7 = new javax.swing.JPanel();
        rbTokenisation = new javax.swing.JRadioButton();
        rbRacinisation = new javax.swing.JRadioButton();
        rbLemmatisation = new javax.swing.JRadioButton();
        jTabbedPane3 = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        btnKMeans = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        txtClusterCount = new javax.swing.JTextField();
        barKmeans = new javax.swing.JProgressBar();
        lblKmeans = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        txtMinkowskiParam = new javax.swing.JTextField();
        rbDistEuclidienne = new javax.swing.JRadioButton();
        rbDistManhattan = new javax.swing.JRadioButton();
        jLabel9 = new javax.swing.JLabel();
        rbDistMinkowski = new javax.swing.JRadioButton();
        jPanel5 = new javax.swing.JPanel();
        rbDistMax = new javax.swing.JRadioButton();
        rbIterations = new javax.swing.JRadioButton();
        jLabel11 = new javax.swing.JLabel();
        txtDistMax = new javax.swing.JTextField();
        txtIterations = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Projet EIT2");

        jLabel1.setText("Chemin Entrainement :");

        txtTrainPath.setText("D:\\CorpusTwitter\\train.txt");

        jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel2.setText("Mots Uniques :");

        lblUniqueWords.setText("?");

        jLabel3.setText("Mots Total :");

        lblTotalWords.setText("?");

        jLabel4.setText("# Tweets :");

        lblTweetCount.setText("?");

        jLabel5.setText("Moyenne # mots  :");

        lblAvgWordCount.setText("?");

        btnMakeStats.setText("Calculer");
        btnMakeStats.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMakeStatsActionPerformed(evt);
            }
        });

        lblMakeStats.setText("0%");

        panelTop20.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        panelTop20.setMaximumSize(new java.awt.Dimension(425, 70));
        panelTop20.setMinimumSize(new java.awt.Dimension(425, 70));

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel7.setText("Top 20");

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel8.setText("Flop 20");

        panelFlop20.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        panelFlop20.setMaximumSize(new java.awt.Dimension(425, 70));
        panelFlop20.setMinimumSize(new java.awt.Dimension(425, 70));
        panelFlop20.setPreferredSize(new java.awt.Dimension(425, 70));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(panelFlop20, javax.swing.GroupLayout.PREFERRED_SIZE, 444, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(panelTop20, javax.swing.GroupLayout.PREFERRED_SIZE, 444, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel3))
                                .addGap(38, 38, 38)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(lblTotalWords, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lblUniqueWords, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jLabel7)
                            .addComponent(jLabel8))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel4))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblTweetCount, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lblAvgWordCount, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(btnMakeStats)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(barMakeStats, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblMakeStats, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(7, 7, 7)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lblMakeStats, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnMakeStats, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(barMakeStats, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(lblUniqueWords))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(lblTotalWords)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(lblTweetCount))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(lblAvgWordCount))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelTop20, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel8)
                .addGap(4, 4, 4)
                .addComponent(panelFlop20, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelTop20.getAccessibleContext().setAccessibleParent(jLabel1);

        jTabbedPane1.addTab("Statistiques", jPanel1);

        jLabel6.setText("Chemin Test :");

        txtTestPath.setText("D:\\CorpusTwitter\\test.txt");

        jPanel2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        cbFilterSW.setSelected(true);
        cbFilterSW.setText("Filtrer mots outil :");

        cbFilterPonctuation.setSelected(true);
        cbFilterPonctuation.setText("Filtrer ponctuation");

        cbFiltrerNombres.setSelected(true);
        cbFiltrerNombres.setText("Filtrer nombres");

        txtStopWordPath.setText("englishST.txt");

        cbFilterAccents.setSelected(true);
        cbFilterAccents.setText("Filtrer accents");

        cbFilterOneOccurence.setSelected(true);
        cbFilterOneOccurence.setText("Filtrer 1 occurence");

        jPanel6.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        rbISO.setText("ISO-8859-1");

        rbUTF8.setSelected(true);
        rbUTF8.setText("UTF-8");
        rbUTF8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbUTF8ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rbUTF8)
                    .addComponent(rbISO))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addComponent(rbUTF8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(rbISO))
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        rbTokenisation.setSelected(true);
        rbTokenisation.setText("Tokenisation");

        rbRacinisation.setText("Racinisation");

        rbLemmatisation.setText("Lemmatisation");
        rbLemmatisation.setEnabled(false);

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rbTokenisation)
                    .addComponent(rbRacinisation)
                    .addComponent(rbLemmatisation))
                .addGap(12, 12, 12))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(rbTokenisation)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rbRacinisation)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rbLemmatisation)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(cbFilterSW)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtStopWordPath, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(104, Short.MAX_VALUE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cbFilterAccents)
                    .addComponent(cbFilterPonctuation)
                    .addComponent(cbFiltrerNombres)
                    .addComponent(cbFilterOneOccurence))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(cbFilterAccents)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbFilterPonctuation)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbFiltrerNombres)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbFilterOneOccurence)
                        .addGap(6, 6, 6))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbFilterSW)
                    .addComponent(txtStopWordPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28))
        );

        jTabbedPane2.addTab("Normalisation", jPanel2);

        jPanel3.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        btnKMeans.setText("Calculer");
        btnKMeans.setEnabled(false);
        btnKMeans.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnKMeansActionPerformed(evt);
            }
        });

        jLabel10.setText("# Clusters :");

        txtClusterCount.setText("20");

        lblKmeans.setText("0%");

        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        txtMinkowskiParam.setText("3");

        rbDistEuclidienne.setText("Euclidienne");

        rbDistManhattan.setSelected(true);
        rbDistManhattan.setText("Manhattan");

        jLabel9.setText("Calcul de la distance :");

        rbDistMinkowski.setText("Minkowski");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9)
                .addGap(18, 18, 18)
                .addComponent(rbDistEuclidienne)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(rbDistManhattan)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rbDistMinkowski)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtMinkowskiParam, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(rbDistEuclidienne)
                    .addComponent(rbDistManhattan)
                    .addComponent(rbDistMinkowski)
                    .addComponent(txtMinkowskiParam, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        rbDistMax.setText("dist max parcourue centroid < ");

        rbIterations.setSelected(true);
        rbIterations.setText("# iterations:");

        jLabel11.setText("Condition arret :");

        txtDistMax.setText("0.5");

        txtIterations.setText("10");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(rbDistMax)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtDistMax, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(rbIterations)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtIterations, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(rbIterations)
                    .addComponent(txtIterations, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rbDistMax)
                    .addComponent(txtDistMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(btnKMeans)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(barKmeans, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblKmeans, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtClusterCount, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addGap(10, 10, 10))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel10)
                        .addComponent(txtClusterCount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(barKmeans, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnKMeans, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblKmeans, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(4, 4, 4))
        );

        jTabbedPane3.addTab("K-moyennes", jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtTestPath)
                            .addComponent(txtTrainPath, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE)))
                    .addComponent(jTabbedPane3)
                    .addComponent(jTabbedPane2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(txtTrainPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(txtTestPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(21, 21, 21)
                        .addComponent(jTabbedPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTabbedPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnMakeStatsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMakeStatsActionPerformed
        btnMakeStats();
    }//GEN-LAST:event_btnMakeStatsActionPerformed

    private void btnKMeansActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnKMeansActionPerformed
        btnKMeans();
    }//GEN-LAST:event_btnKMeansActionPerformed

    private void rbUTF8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbUTF8ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rbUTF8ActionPerformed

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(UserInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(UserInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(UserInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(UserInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new UserInterface().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JProgressBar barKmeans;
    private javax.swing.JProgressBar barMakeStats;
    private javax.swing.JButton btnKMeans;
    private javax.swing.JButton btnMakeStats;
    private javax.swing.ButtonGroup buttonGroupCondArretKMeans;
    private javax.swing.ButtonGroup buttonGroupDistances;
    private javax.swing.ButtonGroup buttonGroupEncodage;
    private javax.swing.ButtonGroup buttonGroupNormalisation;
    private javax.swing.JCheckBox cbFilterAccents;
    private javax.swing.JCheckBox cbFilterOneOccurence;
    private javax.swing.JCheckBox cbFilterPonctuation;
    private javax.swing.JCheckBox cbFilterSW;
    private javax.swing.JCheckBox cbFiltrerNombres;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTabbedPane jTabbedPane2;
    private javax.swing.JTabbedPane jTabbedPane3;
    private javax.swing.JLabel lblAvgWordCount;
    private javax.swing.JLabel lblKmeans;
    private javax.swing.JLabel lblMakeStats;
    private javax.swing.JLabel lblTotalWords;
    private javax.swing.JLabel lblTweetCount;
    private javax.swing.JLabel lblUniqueWords;
    private javax.swing.JPanel panelFlop20;
    private javax.swing.JPanel panelTop20;
    private javax.swing.JRadioButton rbDistEuclidienne;
    private javax.swing.JRadioButton rbDistManhattan;
    private javax.swing.JRadioButton rbDistMax;
    private javax.swing.JRadioButton rbDistMinkowski;
    private javax.swing.JRadioButton rbISO;
    private javax.swing.JRadioButton rbIterations;
    private javax.swing.JRadioButton rbLemmatisation;
    private javax.swing.JRadioButton rbRacinisation;
    private javax.swing.JRadioButton rbTokenisation;
    private javax.swing.JRadioButton rbUTF8;
    private javax.swing.JTextField txtClusterCount;
    private javax.swing.JTextField txtDistMax;
    private javax.swing.JTextField txtIterations;
    private javax.swing.JTextField txtMinkowskiParam;
    private javax.swing.JTextField txtStopWordPath;
    private javax.swing.JTextField txtTestPath;
    private javax.swing.JTextField txtTrainPath;
    // End of variables declaration//GEN-END:variables
}
